package com.zeropol2.anyquestion.component.ui.listitem;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zeropol2.anyquestion.R;

/**
 * 글 목록 아이템
 * @author zeropol2
 *
 */
public class ArticleView extends LinearLayout {

	private Context mContext;
	private LayoutInflater mInflater;
	private LinearLayout mLayout;
	private TextView mTitle;
	private TextView mDate;
	private TextView mReplyCount;

	public ArticleView(Context context) {
		super(context);
		mContext = context;
		init();
	}

	public ArticleView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;
		init();
	}

	private void init() {
		mInflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mLayout = (LinearLayout) mInflater.inflate(R.layout.article_view, this);
		
		mTitle = (TextView)mLayout.findViewById(R.id.article_view_title);
		mDate = (TextView)mLayout.findViewById(R.id.article_view_date);
		mReplyCount = (TextView)mLayout.findViewById(R.id.article_view_reply_count);
	}
	
	
	
	/**
	 * 제목 설정
	 * @param title
	 */
	public void setTitle(String title) {
		mTitle.setText(title);
	}
	
	/**
	 * 제목 반환
	 * @return
	 */
	public String getTitle() {
		return mTitle.getText().toString();
	}
	

	/**
	 * 작성일 설정
	 * @param date
	 */
	public void setDate(long date) {
		DateFormat df = new SimpleDateFormat("HH:mm:ss");
		mDate.setText(df.format(date));
	}
	
	/**
	 * 작성일 반환
	 * @return
	 */
	public String getDate() {
		return mDate.getText().toString();
	}
	
	/**
	 * 댓글 수 설정
	 * @param count
	 */
	public void setReplyCount(int count) {
		mReplyCount.setText("[" + count + "]");
	}
	
	/**
	 * 댓글수 반환
	 * @return
	 */
	public String getReplyCount() {
		return mReplyCount.getText().toString();
	}

}
